This notebook converts WAV files in the specified 'directory' into FLAC format with the specified sampling 'rate' and bit 'depth'.
directory – directory containing WAV files
rate – sampling rate (Hertz)
depth – bit depth (bits)
In [ ]:
directory = ""
In [2]:
rate = 48000
In [3]:
depth = 16
In [1]:
import subprocess
import os.path
from os import listdir
In [46]:
os.chdir(directory)
os.chdir(os.pardir)
converted_directory = os.path.abspath(os.curdir) + '/converted'
if os.path.exists(converted_directory):
os.rmdir(converted_directory)
os.mkdir(converted_directory)
In [47]:
WAV_files = [f for f in listdir(directory) if os.path.isfile(os.path.join(directory, f)) and f.split('.')[1] == 'WAV']
In [48]:
for filename in WAV_files:
infilename = './clipped/' + filename
outfilename = './converted/' + filename
subprocess.check_output(["sox", infilename, "-r", str(rate), "-b", str(depth), outfilename])
In [49]:
for filename in WAV_files:
infilename = './converted/' + filename
subprocess.check_output(["flac", infilename])